package com.jyw.system.domain.dto;

import com.jyw.common.constant.Constants;
import com.jyw.common.core.domain.entity.SysDept;
import com.jyw.common.utils.DateUtils;
import com.jyw.common.utils.bean.BeanUtils;
import com.jyw.system.domain.SysContact;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 沈峻
 * @ClassName DeptAddDto
 * @Description TODO
 * @Date 2023/8/10 10:35
 **/
@ApiModel("新增第三方科室请求实体")
@Data
public class DeptThirdAddDto {

    @ApiModelProperty("部门名称")
    @NotBlank(message = "名称不能为空")
    private String deptName;

    @ApiModelProperty("部门编号")
    private String deptCode;

    @ApiModelProperty("部门地址")
    private String deptPlace;

    @ApiModelProperty("备注")
    private String deptRemark;

    @ApiModelProperty("联系人")
    private List<DeptContactDto> contact;

    public SysDept buildThird() {
        SysDept dept = new SysDept();
        BeanUtils.copyProperties(this,dept);
        dept.setDeptType(1);
        dept.setDelFlag("0");
        dept.setStatus("0");
        dept.setCreateTime(DateUtils.getNowDate());
        return dept;
    }

    public List<SysContact> buildContact(SysDept dept) {
        return contact.stream().map(data -> {
            SysContact sysContact = new SysContact();
            BeanUtils.copyProperties(data, sysContact);
            sysContact.setPhone(data.getPhone().stream().collect(Collectors.joining(Constants.SEPARATOR)));
            sysContact.setDeptId(dept.getDeptId());
            return sysContact;
        }).collect(Collectors.toList());
    }
}
